import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
import ArraySort.*;

public class MySortDemo {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Random rand = new Random();
        System.out.print("Enter the length of the array:");
        int len = sc.nextInt();
        int[] a = new int[len];
        int[] b = new int[len];
        int[] c = new int[len];
        int[] d = new int[len];
        //为了防止排序好后的数组重新排序，安排四个内容一样的数组对四个算法进行操作

        for (int i = 0; i < len; i++) {
            a[i] = rand.nextInt(5000);
        }
        //随机产生测试类数据
        for(int i = 0; i < len; i++)
        {
            b[i]=a[i];
            c[i]=a[i];
            d[i]=a[i];
        }
        //每个算法安排相同的数据

        display(a, " selectionSort ", " before");//排序前数组内数据展示
        long startTimeNs = System.nanoTime();//开始计时
        SelectionSort.selectionSort(a);//开始算法操作
        long endTimeNs = System.nanoTime();//停止计时
        display(a, " selectionSort ", " after");//排序后数组内数据展示
        System.out.println("selectionSort time: " + (endTimeNs - startTimeNs) + "ns");//计算算法所需时间
        System.out.println("----------------------------------------------------");//间隔

        display(b, " bubbleSort ", " before");//排序前数组内数据展示
        startTimeNs = System.nanoTime();//开始计时
        BubbleSort.bubbleSort(b);//开始算法操作
        endTimeNs = System.nanoTime();//停止计时
        display(b, " bubbleSort ", " after");//排序后数组内数据展示
        System.out.println("bubbleSort time: " + (endTimeNs - startTimeNs) + "ns");//计算算法所需时间
        System.out.println("----------------------------------------------------");//间隔

        display(c, " insertSort ", " before");//排序前数组内数据展示
        startTimeNs = System.nanoTime();//开始计时
        int []temp=InsertSort.insertSort(c);//开始算法操作
        endTimeNs = System.nanoTime();//停止计时
        display(temp, " insertSort ", " after");//排序后数组内数据展示
        System.out.println("insertSort time: " + (endTimeNs - startTimeNs) + "ns");//计算算法所需时间
        System.out.println("----------------------------------------------------");//间隔

        display(d, " quickSort ", " before");//排序前数组内数据展示
        startTimeNs = System.nanoTime();//开始计时
        Arrays.sort(d);
        endTimeNs = System.nanoTime();//停止计时
        display(d, " quickSort ", " after");//排序后数组内数据展示
        System.out.println("quickSort time: " + (endTimeNs - startTimeNs) + "ns");//计算算法所需时间
        System.out.println("----------------------------------------------------");//间隔
    }

    public static void display(int[] array, String sort, String when) {
        System.out.println("Array values" + when + sort + "sorting:");
        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i] + " ");
        }
        System.out.println();
    }//展示函数
}
